const connections = require('../app/database')
class PaymentService {
  async submitOrderService(order, orderId) {
    try {
      const { goodsIds, userId, titles, totalPrice, prices, counts, imgUrls } = order
      const state = '未支付' // 未支付状态
      const res = await connections.execute('INSERT INTO `user-order`(orderId, goodsIds, userId, titles, totalPrice, state, counts, prices, imgUrls) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', [orderId, goodsIds, userId, titles, totalPrice, state, counts, prices, imgUrls])
      return res[0]
    } catch (error) {
      console.log(error);
    }
  }
  async updateOrderStateSerivce(state, orderId) {
    try {
      const res = await connections.execute('UPDATE `user-order` SET state = ? WHERE orderId = ?', [state, orderId])
      if (res[0].length !== 0) return true
    } catch (error) {
      console.log(error);
    }
  }
}

module.exports = new PaymentService()